 var data_a;
new Vue({
				el: '#app',
				data: function() {
					return {
						lvliang:true, kongqiwendu:true, co2:true, shidu:true, fengxiang:true, fengsu:true,qixiang:false,zhexiantuo:true,buttonct:'表格展示',
						userPhone:null,
			            userName:null,
						quyu: null,
						info: null,
						ment: null,
						zexiantu:null,
						zexiantu2:null,
						qixiangxiti:null,
						culiqinxiang:null,
						cName: '',
						address: '',
						contacts: '',
						cellphone: '',
						telephone: '',
						fax: '',
						email: '',
						website: '',
						copyright: '',
						remark: '',
						webName: '',
						loading: true,
						miaoqing: null,
						parms: null,
						currentPage: 1,
						pageSize: 30,
						currentTotal: 0,
						pickerOptions: {
							shortcuts: [{
								text: '最近一周',
								onClick(picker) {
									const end = new Date();
									const start = new Date();
									start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
									picker.$emit('pick', [start, end]);
								}
							}, {
								text: '最近一个月',
								onClick(picker) {
									const end = new Date();
									const start = new Date();
									start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
									picker.$emit('pick', [start, end]);
								}
							}, {
								text: '最近三个月',
								onClick(picker) {
									const end = new Date();
									const start = new Date();
									start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
									picker.$emit('pick', [start, end]);
								}
							}]

						},
						value: '',
						queryParams: {
							pageNum: 1,
							pageSize: 10,
							deptName: undefined,
							roleName: undefined,
							roleKey: undefined,
							status: undefined
						},
						gongshiou1: [],
						gongshiou2: [],
						gongshiou: [],
						// 日期范围
						dateRange: [],

						// 非单个禁用
						single: true,

					}
				},
				created() {
					//this.quyu = this.gongshiou[0].areaId;
				},
				mounted() {

					//获取菜单
					axios(basePath + '/menu/findMenuList.do', {
						method: 'GET',
						mode: 'no-cors',
						headers: {
							'Access-Control-Allow-Origin': '*',
							'Content-Type': 'application/json',
						},
						withCredentials: true,
						credentials: 'same-origin',
					}).then(response => {

						
						if(response.data.state) {
							this.ment = response.data.data
						} else {
							alert(response.data.msg)
							window.location.href = "../login/index.html"
						}

					}).catch(function(error) { // 请求失败处理
						console.log(error);
					});

					//获取区域
					axios(basePath + '/area/selectAreaByEquipmnt.do', {
						method: 'post',
						mode: 'no-cors',
						headers: {
							'Access-Control-Allow-Origin': '*',
							'Content-Type': 'application/json',
						},
						withCredentials: true,
						credentials: 'same-origin',
						data: {
							"eqType": "3",
							"eqModel": "0"
						}
					}).then(response => {
						if(response.data.state) {
							console.log(response)
							this.gongshiou = response.data.data;
							this.userPhone=getCookie('userPhone');
						this.userName=getCookie('userName');
//							this.quyu = this.gongshiou[0].areaId;
							//				this.Rolechanges = this.gongshiou[0].areaId;
						} else {
							alert(response.data.msg)
							window.location.href = "../login/index.html"
						}

					}).catch(function(error) { // 请求失败处理
						console.log(error);
					});

					this.getList()

				},
				methods: {
					handleSizeChange(val) {
						this.pageSize = val;
						console.log(`每页 ${val} 条`);
					},
					handleCurrentChange(val) {
						this.currentPage = val;
						console.log(`当前页: ${val}`);
						this.getList()

					},
					currentPage(val) {
						console.log(val);
					},
					getList: function(val) {
						this.loading = true;
						axios(basePath + '/company/queryCompanyList.do', {
							method: 'GET',
							mode: 'no-cors',
							headers: {
								'Access-Control-Allow-Origin': '*',
								'Content-Type': 'application/json',
							},
							withCredentials: true,
							credentials: 'same-origin',
							params: {
								pageSize: 12,
								pageIndex: this.currentPage
							}
						}).then(response => {
							if(response.data.state) {
								this.info = response.data.data
								this.parms = response.data.parms.totalCount
								this.loading = false;
								console.log(response);
							} else {
								alert(res.data.msg)
								window.location.href = "../login/login.html"

							}

						}).catch(function(error) { // 请求失败处理
							console.log(error);
						});
					},
					//获取设备
					Rolechanges(val) {
						//获取设备
						var data1 = {
							areaId: val,
							eqType:"3"
						};
						var this_ = this;
						ajaxType(basePath + '/equipment/selectEquipmentNameBySoil.do', 'get', data1, geturl)

						function geturl(data) {
							console.log(data)
							this_.gongshiou2 = '';
							this_.gongshiou1 = data.data;
							if(data.data == '') {
								this_.$message.error('此区域下的设备为空');
							}
						}

					},

					//获取折线图项目
					getZexiantu(val) {
						const loading = this.$loading({
				          lock: true,
				          text: 'Loading',
				          spinner: 'el-icon-loading',
				          background: 'rgba(0, 0, 0, 0.7)'
				        });
						
						//获取设备
						var data1 = {
							areaId: this.quyu,
							eqId: this.gongshiou2,
							startTime: this.dateRange[0],
							endTime: this.dateRange[1],
							enType:'1'
						};
						//selectSoilMoistureList.do
						//getEnvironmentName.do
						var this_ = this;
						ajaxType(basePath + '/environment/getEnvironmentName.do', 'post', data1, geturl)

						function geturl(data) {
							loading.close();
							console.log("data")
							console.log(data)
                           var data_a=data.data;
							if(data.data == '') {
								this_.$message.error('此设备下的数据为空');
							}
//							this_.zexiantu2 = '';
							this_.zexiantu = data.data;
							
							 var dataName = [];
					            var dataInitial = {};
					            $.each(data_a, function(i,val){
					            	
					            	dataName.push(data_a[i]["name"]);
					            	dataInitial[data_a[i]["name"]] = data_a[i]["value"];
					            });
					            console.log("dataName");
					            console.log(dataName);
					            console.log("dataInitial");
					            console.log(dataInitial);
					            renderHtml(dataName,dataInitial);

						}

					},
					
					//获取折线图数据
					getZexiashuju(val) {
						//获取设备
						var data1 = {
							areaId: this.quyu,
							eqId: this.gongshiou2,
							startTime: this.dateRange[0],
							endTime: this.dateRange[1],
							dateType:'day',
							enType:'1'
						};
						var this_ = this;
						ajaxType(basePath + '/environment/selectSoilMoistureChart.do', 'post', data1, geturl)

						function geturl(data) {
							console.log(data)

							if(data.data == '') {
								this_.$message.error('此设备下的数据为空');
							}
							this_.zexiantu2 = '';
							this_.qixiangxiti=data.data;
							this_.culiqinxiang=data.data.sortKeyToJson("envirName");
							var  echartsData = data.data.sortKeyToJson("envirName");
							console.log(echartsData);
							
							var xdata = [];
				            $.each(echartsData, function(i,val){
				                var t = {}, a = [];
				                $.each(val, function(m,n){
				                    var tVal = n["collecTime"];
				                    xdata.push( tVal);
				                })
				
				            });
				            function uniq(array){
				                var temp = [];
				                var index = [];
				                var l = array.length;
				                for(var i = 0; i < l; i++) {
				                    for(var j = i + 1; j < l; j++){
				                        if (array[i] == array[j]){
				                            i++;
				                            j = i;
				                        }
				                    }
				                    temp.push(array[i]);
				                    index.push(i);
				                }
				                return temp;
				            }
				
				            var cdata = uniq(xdata);
            console.log(cdata);
            
            
            
            var tempArr = [],maxArr= [],minArr=[],typeData=1;
            var res = [];
            $.each(echartsData, function(i,val){
                var t = {},maxData={},minData={}, a = [],max = [],min=[];
                $.each(val, function(m,n){
                    var tVal = n["collecTime"];//.substring(0, n["collecTime"].lastIndexOf(".")).replace(new RegExp("-","gm"),"/");

                    if (typeData == "max"){
                        a.push( [ tVal , Number(n["maxEnvirVale"]) ] );
                    } else if (typeData =="min" ){
                        a.push( [ tVal , Number(n["minEnvirVale"]) ] );
                    }else if (typeData =="vs" ){
                        a.push( [ tVal , Number(n["envirValue"]) ] );
                        max.push( [ tVal , Number(n["maxEnvirVale"]) ] );
                        min.push( [ tVal , Number(n["minEnvirVale"]) ] );
                    }else{
                        a.push( Number(n["envirValue"])  );
                    }
                })
                t[i] = a;//平均值
                maxData[i]=max;//最大值
                minData[i] = min;//最小值
                tempArr.push(t);
                maxArr.push(maxData);
                minArr.push(minData);
            });
            
              console.log(tempArr);  console.log(maxArr)
              console.log(minArr)
              console.log(res)


                  var datac = {
							areaId: this_.quyu,
							eqId: this_.gongshiou2,
							startTime: this_.dateRange[0],
							endTime: this_.dateRange[1],
							enType:'1'
						};
						
						ajaxType(basePath + '/environment/getEnvironmentName.do', 'post', datac, geturl)

						function geturl(data) {

                      var data_c = data.data;
                      $.each(data_c, function(i,val){
                      	
					             shebeizexiantu(data_c[i]["name"],data_c[i]["value"],data_c[i]["value"],tempArr);	
//					            	
					            });	
					           }



            
            //折线图
            function shebeizexiantu(xiangmuName,id_i,id_c,tempArr){
            	var avgData;
            	$.each([xiangmuName],function(i,val){

	                for(var k in tempArr){
	                    if(tempArr[k][val]){
	                        avgData = tempArr[k][val];
	                        break;
	                    }
	                }
            });
            setTimeout(function(){
            echarts_3(cdata,avgData,[xiangmuName],id_i,'#cdba00');	
            },900)
            
            }
            
            
            
            
            
       
						}

					},
					
					
					
					

					//获取设备
					getQxList(val) {
						//获取设备
						var data1 = {
							pageIndex: this.currentPage,
							areaId: this.quyu,
							eqId: this.gongshiou2,
							startTime: this.dateRange[0],
							endTime: this.dateRange[1]
						};
						var this_ = this;

						//	          getEnvironmentName
						axios(basePath + '/environment/getEnvironmentName.do', {
							method: 'post',
							mode: 'no-cors',
							headers: {
								'Access-Control-Allow-Origin': '*',
								'Content-Type': 'application/json',
							},
							withCredentials: true,
							credentials: 'same-origin',
							params: data1
						}).then(response => {
							if(response.data.state) {
								this.info = response.data.data
								this.parms = response.data.parms.totalCount
								this.loading = false;
								if(response.data.data == '') {
									this.$message.error('没有获取到信息哦');
								}
								console.log(response);
							} else {
								alert(res.data.msg)
								window.location.href = "../login/login.html"

							}

						}).catch(function(error) { // 请求失败处理
							console.log(error);
						});
	
					},

					/** 搜索按钮操作 */
					handleQuery() {
						this.queryParams.pageNum = 1;
						this.getZexiantu();
						this.getZexiashuju();
						console.log()
					},
					/** 重置按钮操作 */
					resetQuery() {
//						this.dateRange = [];
//						this.resetForm("queryForm");
//						this.buttonct();
                     var this_=this;
				this_.qixiang= !this_.qixiang;
							this_.zhexiantuo=!this_.zhexiantuo;

					},
					/** 新增按钮操作 */
					handleAdd() {
						this.reset();
						this.opentianjian = true;
						this.title = "添加";
					},

				}
			})


  // 页面渲染
  function renderHtml(dataName,data){
    var carouselBox = $('.carousel-main');
    var len = data.length;
    var str = '';
    var charc = '';
    var carouselBaseParams = {
      "温度": [basePath3 + "environment/wendu.png", "#ff6262"],
      "湿度": [basePath3 + "environment/shidu.png", "#3c81f1"],
      "露点": [basePath3 + "environment/ludian.png", "#2edfe1"],
      "光照": [basePath3 + "environment/guangzhaodu.png", "#f0631e"],
      "蒸发量": [basePath3 + "environment/zhengfaliang.png", "#4caffc"],
      "风向": [basePath3 + "environment/fengxiang.png", "#e96249"],
      "风速": [basePath3 + "environment/fengsu.png", "#7c73f2"],
      "光合": [basePath3 + "environment/gzfs.png", "#ffd051"],
      "雨量": [basePath3 + "environment/jiangyuliang.png", "#00b4f7"],
      "气压": [basePath3 + "environment/daqiya.png", "#b47df8"],
      "Co2": [basePath3 + "environment/c02.png", "#47cafb"],
      "PM2.5": [basePath3 + "environment/PM.png", "#fea356"],
      "氨气": [basePath3 + "environment/anqi.png", "#41ecb8"],
      "紫外辐射": [basePath3 + "environment/zwfs.png", "#daa4f4"],
      "总辐射": [basePath3 + "environment/zongfushe.png", "#5ad3ae"],
      "雨雪": [basePath3 + "environment/yuxue.png", "#30dfff"],
      "日照": [basePath3 + "environment/rizhao.png", "#ff3f19"],
      "PH（玻璃电极）": [basePath3 + "environment/PHqx.png", "#ffee2f"],
      "臭氧": [basePath3 + "environment/qitaTQ.png", "#47cafb"],
      "PM10": [basePath3 + "environment/qitaTQ.png", "#fea356"],
      "SO2": [basePath3 + "environment/eyhl.png", "#41ecb8"],
      "NO2": [basePath3 + "environment/qitaTQ.png", "#daa4f4"],
      "CO": [basePath3 + "environment/qitaTQ.png", "#5ad3ae"],
      "噪音": [basePath3 + "environment/qitaTQ.png", "#30dfff"],
      "负氧离子": [basePath3 + "environment/qitaTQ.png", "#ff3f19"],
      "其他": [basePath3 + "environment/qitaTQ.png", "#ff3091"],
      "硬度": [basePath3 + "environment/yingdu.png", "#ffcf2b"],
      "土壤温度":[basePath3 + "environment/trwd.png", "#ff9032"],
      "土壤水分": [basePath3 + "environment/trsd.png", "#6c89f5"],
      "土壤盐分": [basePath3 + "environment/tryf.png","#2fe083"],
      "液位": [basePath3 + "environment/sfswei.png", "#ffcf2b"],
      "水电导率": [basePath3 + "environment/sfddl.png", "#6c89f5"],
      "溶解氧": [basePath3 + "environment/sfrjy.png","#2fe083"],
      "水温": [basePath3 + "environment/sfswen.png", "#ffee2f"],
      "浊度": [basePath3 + "environment/sfzd.png", "#fea35f"],
      "水盐度": [basePath3 + "environment/sfyd.png", "#ff0e2f"],
      "水叶绿素": [basePath3 + "environment/sfyls.png", "#afef2f"],
      "悬浮物": [basePath3 + "environment/sfxfw.png", "#00ef2f"] 
    };
    var carouselOptionParams = [];

    $.each(carouselBaseParams, function(i,j){
      $.each(dataName, function(m,n){
        if(n.indexOf(i) !== -1){
          var initial = data[n];
          carouselOptionParams.push(n);
          console.log(initial)
          console.log(j[0])
          console.log(j[1])
          console.log(n)
 
          str += '<div  class="col-xl-2 col-lg-3 col-sm-4 col-6 ">';
          str += '<div class="contacts__item">';
          str += '<a href="javacript:void(0);" class="contacts__img">';
          str += '<img src="'+ j[0] +'" alt="">';
          str += '</a>';
          str += '<div class="contacts__info">';
          str += '<small>'+n+'</small>';
          str += '</div>';
          str += '<input type="checkbox" class="my-checkbox" id="'+initial+'_" checked="checked"  data-initial="'+ initial +'" data-color="'+ j[1] +'" value="'+ n +'" />';
          str += '</div>';
          str += '</div>';
          
          charc += '<div  class="boxall echart3 chare '+initial+'">';
          charc += '<div class="alltitle">'+ n +'统计</div>';
          charc += '<div class="navboxall" id="'+ initial +'"></div>';
          charc += '</div>';
          
          $(document).on("click",'#'+initial+'_',function(){
	        var check = this.checked;
	        console.log(this.checked)
//	        alert("999999")
	        if (!check){
	            $('#qiXiangCahst>.'+initial).hide();
	        }
	        else{
	            $('#qiXiangCahst>.'+initial).show();
	        }
    }); 
           
           
          
   
        }
      });
    });

if(carouselOptionParams.length > 0){
      var differArr = dataName.diff(carouselOptionParams);
      var differArrLen = differArr.length;
      for(var i = 0;i<differArrLen;i++){
        var initial = data[ differArr[i] ];
        console.log(initial + differArr[i] ) 
         str += '<div  class="col-xl-2 col-lg-3 col-sm-4 col-6" >';
          str += '<div class="contacts__item">';
          str += '<a href="javacript:void(0);" class="contacts__img">';
          str += '<img src="'+basePath3+'environment/qitaTQ.png" alt="">';
          str += '</a>';
          str += '<div class="contacts__info">';
          str += '<small>'+differArr[i]+'</small>';
          str += '</div>';
          str += '<input type="checkbox" class="my-checkbox" checked="checked"  data-initial="'+ initial +'" data-color="#ff3091" value="'+ differArr[i] +'" />';
          str += '</div>';
          str += '</div>';
          
          charc += '<div  class="boxall echart3 chare">';
          charc += '<div class="alltitle">'+ differArr[i] +'统计</div>';
          charc += '<div class="navboxall" id="'+ initial +'"></div>';
          charc += '</div>';
      }
    }







//  if(carouselOptionParams.length > 0){
//    var differArr = dataName.diff(carouselOptionParams);
//    var differArrLen = differArr.length;
//    for(var i = 0;i<differArrLen;i++){
//      var initial = data[ differArr[i] ];
//      console.log(differArr[i]);
//
//    }
//  }
    $("#qiXianglist").html("");
     $("#qiXiangCahst").html("");
    $("#qiXianglist").html(str);
     $("#qiXiangCahst").html(charc);

  }




/*
* 获取选项信息
* @param echartsData:请求的数据
*/
  function getOptionsMsg(echartsData,type,param){
    var tempOptions = [],
        tempColor = [],
        tempUnOptions = [],
        tempAllOptions = [],
        echartsData = echartsData;
      $('.carousel-container :checked').each(function(){
        tempOptions.push($(this).val());
        tempColor.push($(this).data('color'));
      });

      $(".carousel-container input[type='checkbox']").each(function(){
        tempAllOptions.push($(this).val());
      });

      $('.carousel-container input:not(:checked)').each(function(){
        tempUnOptions.push($(this).val());
      });

  }











  // 数组的差
  Array.prototype.diff = function(a) {
    return this.filter(function(i) {return a.indexOf(i) < 0;});
  };






